package com.fgr.controller;

import com.fgr.beans.Donation;
import com.fgr.beans.DonationType;
import com.fgr.beans.User;
import com.fgr.mapper.UserMapper;
import com.fgr.service.DonationService;
import com.fgr.service.DonationTypeService;
import com.fgr.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class DonationTypeController {
    @Autowired
    DonationTypeService donationTypeService;

    @Autowired
    UserService userService;

    @Autowired
    DonationService donationService;

    @GetMapping("findAllDonationType")
    public String findAllDonationType(Model model){
        List<DonationType> donationTypes = donationTypeService.selectAllDonationType();
        model.addAttribute("donationTypes",donationTypes);
        return "foreground/offer";
    }

    @GetMapping("findAllDonationTypeBg")
    public String findAllDonationTypeBg(Model model){
        List<DonationType> donationTypes = donationTypeService.selectAllDonationType();
        List<User> users = userService.selectAllUser();
        model.addAttribute("donationTypes",donationTypes);
        model.addAttribute("users",users);
        return "background/addoffer";
    }

    @GetMapping("findDonationTypeAndUsersAndDonationBg")
    public String findDonationTypeAndUsersAndDonationBg(Integer id,Model model){
        List<DonationType> donationTypes = donationTypeService.selectAllDonationType();
        List<User> users = userService.selectAllUser();
        Donation donation = donationService.selectDonationByDnId(id);

        model.addAttribute("donationTypes",donationTypes);
        model.addAttribute("users",users);
        model.addAttribute("donation",donation);

        return "background/modifyoffer";
    }

    @GetMapping("transferOfferButton")
    public String transferOfferButton(String dnType,String dnTid,HttpSession session){
        session.setAttribute("dnType",dnType);
        session.setAttribute("dnTid",dnTid);

        return "foreground/offer-button";
    }

}
